<?php
class template_item
{
	var $ipsclass;
	var $item;
	
	// Default Item Properties
	var $default_name;
	var $default_description;
	
	// Inherited Properties
	var $allow_multiple = 0;
	var $can_run_multiple = 0;
	
	// When editing/adding the item
	function admin_form() { return ""; }
	
	// When saving the information after editing/adding the item
	function admin_save(&$item_info, $input = array()) { return; }
	
	// When quick saving the price and stock
	// Type possible: 'stockprice'
	function admin_quick_save(&$item_info, $type) { return; }
	
	// When deleting the item via ACP
	function admin_remove() { return; }
	
	// List the file edits
	function admin_view_file_edits() { return ""; }
	
	// When the item is created or bought, returns true to create the item
	function public_on_create_item(&$inv_item, $is_in_acp = 0) { return true; }
	
	// The html for public forum
	function public_use_form($inventory_ids = array()) { return; }
	
	// Creates the form that would be needed for the item
	function public_use_item($inventory_ids = array()) { return; }
	
	// Checks if the input is done
	function input_done($inventory_ids = array()){ return true; }
	
	// When the item is resold. Returns true if allow to resold or resold successfully
	function public_on_resold_item(&$inv_item, $is_in_acp = 0) { return true; }
	
	// When the item is being restocked
	function on_item_restock(&$item) { return; }
	
	// When the item is being listed in the store
	function parse_store_description() { return $this->item['item_description']; }
	
	// When the item is being listed in the inventory as a group
	function parse_group_description($inv_items=array()) { return $this->item['item_description']; }
	
	// When the item is being listed in the inventory by itself
	function parse_single_description($inv_item=array()) { return $this->item['item_description']; }
	
	function load_item(&$item)
	{
		$this->item = &$item;
	}
	
	// Do not overwrite
	function delete_items($inventory_ids)
	{
		if(!is_array($inventory_ids) || count($inventory_ids) == 0)
		{
			return;
		}
		
		$this->ipsclass->DB->build_and_exec_query(array('delete'=>'market_inventory','where'=>"i_id IN (".implode(", ",$inventory_ids).")"));
	}
	
	function _get_hidden_fields($inventory_ids)
	{
		$this->base_url = $this->ipsclass->market_class->base_url."CODE=item";
		$hidden = "<input type='hidden' name='item' value='".$this->item['item_id']."' />\n";
		foreach($inventory_ids as $inv_id)
		{
			$hidden	.= "<input type='hidden' name='item_id[".$inv_id."]' value='".$inv_id."' />\n";
		}
		
		return $hidden;
	}
	
	function _write_log($inv_id,$message = "")
	{
		$this->ipsclass->DB->do_insert('market_item_logs',array(
																	'member_id' => $this->ipsclass->member['id'],
																	'item_id' => $this->item['item_id'],
																	'inv_id' => $inv_id,
																	'ip_address' => $this->ipsclass->ip_address,
																	'l_time' => time(),
																	'log_message' => $message,
										)						);
	}
}
?>